<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<style>
.all_list select {
	width: 120px;
}
</style>
<div class="r_location">
	<i class="r_txtico"></i> 数据统计 &gt; 数据统计管理
</div>
<div class="m-t10">
		<div style="padding: 20px;">
			<span>条件查询：</span>
			<select id="type">
					<option value="">请选择</option>
			 		<c:forEach var="statistic" items="${statistics}">
			 			<option value="${statistic.code}" >${statistic.desc}</option>
			 		</c:forEach>
			 	</select>
			 <span style="padding-left: 20px;">开始日期:</span>
			 <input id="startDate" class="Wdate" type="text" onFocus="WdatePicker({lang:'zh-cn'})"/>
			 <span style="padding-left: 20px;">结束日期:</span>	
			 <input id="endDate" class="Wdate" type="text" onFocus="WdatePicker({lang:'zh-cn'})"/>
			 <span style="padding-left: 20px;"></span>
			 <input type="button" value="搜索" id="seach"/>
		</div>
		
	<div class="clearfix table_fn">
			<span class="l">数据统计列表</span> 
			<span class="r" style="_margin-top: 5px;">
			<span id="totalText" style="font-size: 16px;color: #FFF;padding-right: 20px;" ></span>
			</span>
	</div>
	<table id="report_table">
	</table>
	<div id="pgtoolbar"></div>
</div>

<script>
	$(function() {
		$.ajax({
			type : "post",
			dataType : 'json',
			async : false,
			url : '/ph-cms/cms/report/reports',
			data : {},
			success : function(data) {
				console.log(data.data);
				$("#totalText").text("");
				var text = "总用户数:"+data.data.userCountTotal 
				+" , 用户数:"+data.data.userTotal+" , 借款用户数:"
				+data.data.loanTotal+", 借款金额:"+data.data.loanamount 
				+" , 还款人数:"+data.data.repaymentUser+" , 还款金额"+data.data.repaymentamount;
				$("#totalText").text(text);
			}
		});
		$.jgrid.ajaxOptions.type = 'post';
		$("#report_table").jqGrid({
			url : "/ph-cms/cms/report/reportData",
			datatype : "json",
			colModel : [
			    {
				label : '用户总数',
				name : 'totalUser',
				index : 'totalUser',
				width:50
			}, {
				label : '类型',
				name : 'type',
				index : 'type',
				width:60
			}, {
				label : '时间',
				name : 'createDate',
				index : 'createDate',
				width:50
			}, {
				label : '金额',
				name : 'amountOfMoney',
				index : 'amountOfMoney',
				width:100,
				align:'left'
			}],
			height : 370,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			viewrecords : true,
			pager : '#pgtoolbar',
			autowidth : true,
			rownumbers : true,
			jsonReader : {
				root : "data",//当前记录
				page : "index",
				records : "totalRecord",//总记录数
				total : 'total',//总页数
				repeatitems : false
			}
			
		});
		$("#seach").bind('click',function(){
			var startDate = $("#startDate").val();
			var endDate = $("#endDate").val();
			if((startDate != undefined && startDate != null) && (endDate != undefined && endDate != null)){
				if(!compareDate(startDate,endDate)){
					return false;
				}
			}
			var param = {
				"startDate":$("#startDate").val(),
				"endDate":$("#endDate").val(),
				"type":$("#type").val()
			};
			$.ajax({
				type : "post",
				dataType : 'json',
				async : false,
				url : '/ph-cms/cms/report/reports',
				data : param,
				success : function(data) {
					$("#totalText").text("");
					var text = "总用户数:"+data.data.userCountTotal 
					+",用户数:"+data.data.userTotal+",借款用户数:"
					+data.data.loanTotal+",借款金额:"+data.data.loanamount 
					+",还款人数:"+data.data.repaymentUser+",还款金额"+data.data.repaymentamount;
					$("#totalText").text(text);
				}
			});
			var postData = $("#report_table").jqGrid("getGridParam","postData");
			$.extend(postData, param);
			$("#report_table").jqGrid("setGridParam",{datatype : "json"}).trigger("reloadGrid", [{page : 1}]);
		});
		
		
	});	
	
	//比较日前大小  
	function compareDate(checkStartDate, checkEndDate) {      
	    var arys1= new Array();      
	    var arys2= new Array();      
		if(checkStartDate != null && checkEndDate != null) {      
		    arys1=checkStartDate.split('-');      
		      var sdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2]);      
		    arys2=checkEndDate.split('-');      
		    var edate=new Date(arys2[0],parseInt(arys2[1]-1),arys2[2]);      
		if(sdate > edate) {      
		    alert("日期开始时间不能大于结束时间");         
		    return false;         
		}else{   
		    return true;      
		  }   
		}      
	}  
</script>